package com.shouyoudao.changesystemtime;

import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.io.DataOutputStream;
import java.io.IOException;


public class MainActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //获取启动按钮
        Button start = (Button)findViewById(R.id.button);
        //获取移除按钮
        Button remove = (Button)findViewById(R.id.button2);
        //绑定监听
        start.setOnClickListener(new View.OnClickListener()
        {

            @Override
            public void onClick(View v)
            {
                EditText editText = (EditText)findViewById(R.id.editText);
                EditText editText2 = (EditText)findViewById(R.id.editText2);
                EditText editText3 = (EditText)findViewById(R.id.editText3);
                EditText editText4 = (EditText)findViewById(R.id.editText4);
                String curtime = editText.getText().toString();
                curHour = 0;
                curMin = 0;
                dayStep = Integer.parseInt(editText2.getText().toString());
                hourStep = Integer.parseInt(editText3.getText().toString());
                minStep = Integer.parseInt(editText4.getText().toString());
                MainActivity.curtime = Integer.parseInt(curtime);
                // TODO Auto-generated method stub
                Intent intent = new Intent(MainActivity.this, FxService.class);
                //启动FxService
                startService(intent);
                finish();
            }
        });

        remove.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                //uninstallApp("com.phicomm.hu");
                Intent intent = new Intent(MainActivity.this, FxService.class);
                //终止FxService
                stopService(intent);
            }
        });
    }

    private void startRun(){
        ChangeDateRunnable runnable = new ChangeDateRunnable();
        Thread t = new Thread(runnable,"run");
        t.start();

    }

    private class ChangeDateRunnable implements Runnable {

        int time = 20001212;
        @Override
        public void run() {
            while(true) {
                try {
                    Thread.sleep(30000,0);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                time += 1;
                Log.d("test", "fuck!!!!!!!!!");
            }
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public static int curtime = 20161212;
    public static int curHour = 0;
    public static int curMin = 0;
    public static int dayStep = 0;
    public static int hourStep = 0;
    public static int minStep = 0;

}
